﻿using System;
using System.Collections.Generic;

namespace Sandy.Selectors
{
    // Path: client.Family("name")[keys]
    public class RangeColumnSelector
    {
        private readonly SandyClient _client;
        private readonly SandyFamily _family;
        private readonly IEnumerable<string> _keys;
        private readonly KeyRange _keyRange;

        internal RangeColumnSelector(SandyClient client, SandyFamily family, KeyRange keyRange)
        {
            _client = client;
            _family = family;
            _keyRange = keyRange;

            if (keyRange == null) throw new ArgumentException("KeyRange cannot be null");
        }

        internal RangeColumnSelector(SandyClient client, SandyFamily family, IEnumerable<string> keys)
        {
            _client = client;
            _family = family;
            _keys = keys;

            if (keys == null) throw new ArgumentException("Keys cannot be null");
        }

        public IDictionary<string, IDictionary<string, string>> AllColumns
        {
            get
            {
                return this[Range.AllInclusive];
            }
        }

        public IDictionary<string, string> this[string col]
        {
            get
            {
                // throw new NotImplementedException("request 34: get_range_slices(cf={0}, keyRange={1}, col={2}");
                if (_keyRange != null)
                    return GetRangeSlicesQuery.Perform(_client, _family, _keyRange, col);

                return MultigetSliceQuery.Perform(_client, _family, _keys, col);
            }
        }

        public IDictionary<string, IDictionary<string, string>> this[IEnumerable<string> cols]
        {
            get
            {
                // throw new NotImplementedException("request 25: get_range_slices(cf={0}, keyRange={1}, cols={2}");
                if (_keyRange != null)
                    return GetRangeSlicesQuery.Perform(_client, _family, _keyRange, cols);

                return MultigetSliceQuery.Perform(_client, _family, _keys, cols);
            }
        }

        public IDictionary<string, IDictionary<string, string>> this[params string[] cols]
        {
            get
            {
                // Request 26
                return this[(IEnumerable<string>) cols];
            }
        }

        public IDictionary<string, IDictionary<string, string>> this[Range colRange]
        {
            get
            {
                // throw new NotImplementedException("request 27: get_range_slices(cf={0}, keyRange={1}, colRange={2}");
                if (_keyRange != null)
                    return GetRangeSlicesQuery.Perform(_client, _family, _keyRange, colRange);

                return MultigetSliceQuery.Perform(_client, _family, _keys, colRange);

            }
        }
    }
}